#include "include/printf.h"

void printf(unsigned char *str, ...)
{
	va_list args;
	va_start(args,str);
	unsigned char buf[255];
	unsigned int num;
	while(*str != '\0')
	{
		if(*str == '%')
		{
			str++;
			if(*str == 'd' || *str == 'i')
			{
				num = va_arg(args, unsigned int);
				num2str(num,&buf,10);
				printf(buf);
			}
			else if(*str == 'x')
			{
				num = va_arg(args, unsigned int);
				num2str(num,&buf,16);
				printf("0x");
				printf(buf);
			}
			else if(*str == 'o')
			{
				num = va_arg(args, unsigned int);
				num2str(num,&buf,8);
				printf(buf);
				printf("o");
			}
			else if(*str == 'b')
			{
				num = va_arg(args, unsigned int);
				num2str(num,&buf,2);
				printf(buf);
				printf("b");
			}
			else if(*str == 'c')
			{
				unsigned char ch = va_arg(args, unsigned char);
				printf(&ch);
			}
			else if(*str == 's')
			{
				printf(va_arg(args, char*));
			}
		}
		else if(*str == '\n')
		{
			putch('\n');
		}
		else if(*str >= ' ')
		{
			putch(*str);
		}
		str++;
	}
	va_end();
}
